package com.xsherl.leetcode.solution;

import com.xsherl.leetcode.base.ListNode;


public class RemoveDuplicatesFromSortedList {

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null){
            return head;
        }
        ListNode node = head;
        while (node != null){
            int val = node.val;
            // 删除后面的重复元素
            while (node.next != null && val == node.next.val){
                node.next = node.next.next;
            }
            node = node.next;
        }
        return head;
    }

    public static void main(String[] args) {
        ListNode head = ListNode.build(1, 1,2,3,3,3,4,4,5,5);
        ListNode listNode = new RemoveDuplicatesFromSortedList().deleteDuplicates(head);
        System.out.println(listNode);
    }

}
